package com.ncp.model.biz.registerlogin;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.ncp.model.dao.DB;
import com.ncp.model.dao.DbConnection;
import com.ncp.model.entity.registerlogin.UserBasicBean;
import common.util.security.EncryptUtil;

public class checkPwdBiz {
	private DB common=new DB();
	private PreparedStatement pstmt=null;
	private Connection conn=null;
	private ResultSet rs=null;
	
	public int checkUserPsd(String userLoginName,String inputpassWord){
		UserBasicBean ubb=new UserBasicBean();
		int result = -1;
		EncryptUtil encryutil = new EncryptUtil();
		String Shapassword = encryutil.sha(inputpassWord);
		/**
		 * 根据不同的返回值，判断对应的状态信息
		 * -1代表不是注册用户。
		 * 1代表用户是注册用户 
		 */
		String sql = "select * from USERBASIC where UserLoginName='"+userLoginName+"' and PassWord='"+Shapassword+"'";		
		try {
			conn=DbConnection.getConnByDataSource();
			pstmt=conn.prepareStatement(sql);
			rs=pstmt.executeQuery();
			if(rs.next()){
				result = 1;
			}
			else {result = -1;}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}finally{
			common.closeSQL(conn, pstmt);
		}	
	return result;
	}
}
